package com.briup.srms.sms.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.srms.sms.bean.DormitoryType;
import com.briup.srms.sms.bean.DormitoryTypeExample;
import com.briup.srms.sms.bean.extend.DormitoryTypeExtend;
import com.briup.srms.sms.dao.DormitoryTypeMapper;
import com.briup.srms.sms.dao.extend.DormitoryTypeExtendMapper;
import com.briup.srms.sms.service.IDormitoryTypeService;
import com.jacky.base.utils.CustomerException;

@Service
public class DormitoryTypeServiceImpl implements IDormitoryTypeService {
	
	@Autowired
	private DormitoryTypeMapper dormitoryTypeMapper;
	@Autowired
	private DormitoryTypeExtendMapper dormitoryTypeExtendMapper;
	@Override
	public List<DormitoryType> findAll() {
		DormitoryTypeExample example = new DormitoryTypeExample();
		return dormitoryTypeMapper.selectByExample(example);
	}
	@Override
	public List<DormitoryTypeExtend> findAllWidthPhoto() {
		return dormitoryTypeExtendMapper.selectAllWidthPhoto();
	}
	@Override
	public void saveOrUpdate(DormitoryType type) throws CustomerException {
		if(type.getId() == null) {
			dormitoryTypeMapper.insert(type);
		} else {
			dormitoryTypeMapper.updateByPrimaryKey(type);
		}
	}
	@Override
	public void deleteById(long id) throws CustomerException {
		DormitoryType type = dormitoryTypeMapper.selectByPrimaryKey(id);
		if(type == null) {
			throw new CustomerException("要删除的信息不存在");
		}
		dormitoryTypeMapper.deleteByPrimaryKey(id);
	}
	@Override
	public DormitoryTypeExtend findById(long id) {
		
		return dormitoryTypeExtendMapper.selectById(id);
	}
}
